package com.credit.jumu.playcard.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.adapter.ChooseListAdapter;
import com.credit.jumu.playcard.bean.HomeInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/20/020.
 */

public class QuitDialog extends Dialog {
	private final Dialog dialog;
	private Context context;
	private TextView notquit, surequit;
	private OnClickCallBack mOnClickCallBack;


	public interface OnClickCallBack {
		public void onQuitClick();
		public void notQuitClick();
	}

	class OnQuitClick implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			if (mOnClickCallBack != null) {
				mOnClickCallBack.onQuitClick();
			}
		}
	}
	class NotQuitClick implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			if (mOnClickCallBack != null) {
				mOnClickCallBack.notQuitClick();
			}
		}
	}

	public QuitDialog(@NonNull Activity context, final OnClickCallBack mOnClickCallBack) {
		super(context);
		this.context = context;
		dialog = new Dialog(context, R.style.ListDialogStyle);
		dialog.setContentView(R.layout.dialog_quit);
		notquit = dialog.findViewById(R.id.notquit);
		surequit = dialog.findViewById(R.id.surequit);
		Window dialogWindow = dialog.getWindow();
		dialogWindow.setGravity(Gravity.BOTTOM);
		WindowManager.LayoutParams layoutpara = dialogWindow
				.getAttributes();
		dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		layoutpara.width = context.getWindow().getAttributes().width;
		dialogWindow.setAttributes(layoutpara);
		this.mOnClickCallBack = mOnClickCallBack;
		surequit.setOnClickListener(new OnQuitClick());
		notquit.setOnClickListener(new NotQuitClick());
	}


	public void showDialog() {
		if (null != dialog) {
			dialog.show();
		}
	}

	public void cancelDialog() {
		if (null != dialog || dialog.isShowing()) {
			dialog.cancel();
		}
	}
}
